package com.xqb.modules.controller.market;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.MktExchangeCode;
import com.xqb.modules.service.IMktExchangeCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 兑换码Controller
 * 
 * @author xqb
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/market/exchange_code")
public class MktExchangeCodeController extends BaseController
{
    @Autowired
    private IMktExchangeCodeService mktExchangeCodeService;

    /**
     * 查询兑换码列表
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:list')")
    @GetMapping("/list")
    public TableDataInfo list(MktExchangeCode mktExchangeCode)
    {
        startPage();
        List<MktExchangeCode> list = mktExchangeCodeService.selectMktExchangeCodeList(mktExchangeCode);
        return getDataTable(list);
    }

    /**
     * 导出兑换码列表
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:export')")
    @Log(title = "兑换码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MktExchangeCode mktExchangeCode)
    {
        List<MktExchangeCode> list = mktExchangeCodeService.selectMktExchangeCodeList(mktExchangeCode);
        ExcelUtil<MktExchangeCode> util = new ExcelUtil<MktExchangeCode>(MktExchangeCode.class);
        util.exportExcel(response, list, "兑换码数据");
    }

    /**
     * 获取兑换码详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mktExchangeCodeService.selectMktExchangeCodeById(id));
    }

    /**
     * 新增兑换码
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:add')")
    @Log(title = "兑换码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MktExchangeCode mktExchangeCode)
    {
        return toAjax(mktExchangeCodeService.insertMktExchangeCode(mktExchangeCode));
    }

    /**
     * 修改兑换码
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:edit')")
    @Log(title = "兑换码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MktExchangeCode mktExchangeCode)
    {
        return toAjax(mktExchangeCodeService.updateMktExchangeCode(mktExchangeCode));
    }

    /**
     * 删除兑换码
     */
    @PreAuthorize("@ss.hasPermi('market:exchange_code:remove')")
    @Log(title = "兑换码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mktExchangeCodeService.deleteMktExchangeCodeByIds(ids));
    }
}
